package dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;



public class DB_Connection {
	private static DB_Connection isntance;
	private Connection con;
	private String host = "jdbc:mysql://localhost/";/*"jdbc:sqlserver://localhost:1433;databaseName="*/
	private String unicode = "?setUnicode=true&characterEncoding=UTF-8";
	private String dataBase = "pttk";
	private String user = "root";
	private String pwd = "";
	
	public Connection getConnection() {
		try {
			//Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
			Class.forName("com.mysql.jdbc.Driver").newInstance();
			con = DriverManager.getConnection(
					host + dataBase+ unicode,
					user, pwd);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return con;
	}

	public void close() {
		try {
			con.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public static DB_Connection getIsntance() {
		if (isntance == null) {
			isntance = new DB_Connection();
		}
		return isntance;
	}

	public static void main(String[] args) {
		System.out.println(DB_Connection.getIsntance().getConnection());
	}
}
